package com.soilflow.web.controller.soilflow;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.soilflow.common.domain.SysConsultation;
import com.soilflow.info.service.ISysConsultationService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.soilflow.common.annotation.Log;
import com.soilflow.common.core.controller.BaseController;
import com.soilflow.common.core.domain.AjaxResult;
import com.soilflow.common.enums.BusinessType;
import com.soilflow.common.utils.poi.ExcelUtil;
import com.soilflow.common.core.page.TableDataInfo;

/**
 * 用户咨询信息Controller
 * 
 * @author party
 * @date 2023-09-15
 */
@RestController
@RequestMapping("/system/consultation")
public class SysConsultationController extends BaseController {

    @Autowired
    private ISysConsultationService sysConsultationService;

    /**
     * 查询通知公告列表
     */
    @PreAuthorize("@ss.hasPermi('system:consultation:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysConsultation sysConsultation)
    {
        startPage();
        List<SysConsultation> list = sysConsultationService.selectSysConsultationList(sysConsultation);
        return getDataTable(list);
    }

    /**
     * 导出通知公告列表
     */
    @PreAuthorize("@ss.hasPermi('system:consultation:export')")
    @Log(title = "通知公告", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysConsultation sysConsultation) {
        List<SysConsultation> list = sysConsultationService.selectSysConsultationList(sysConsultation);
        ExcelUtil<SysConsultation> util = new ExcelUtil<SysConsultation>(SysConsultation.class);
        util.exportExcel(response, list, "通知公告数据");
    }

    /**
     * 获取通知公告详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:consultation:query')")
    @GetMapping(value = "/{noticeId}")
    public AjaxResult getInfo(@PathVariable("noticeId") Long noticeId)
    {
        return AjaxResult.success(sysConsultationService.selectSysConsultationByNoticeId(noticeId));
    }

    /**
     * 新增通知公告
     */
    @PreAuthorize("@ss.hasPermi('system:consultation:add')")
    @Log(title = "通知公告", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysConsultation sysConsultation)
    {
        return toAjax(sysConsultationService.insertSysConsultation(sysConsultation));
    }

    /**
     * 修改通知公告
     */
//    @PreAuthorize("@ss.hasPermi('system:consultation:edit')")
//    @Log(title = "通知公告", businessType = BusinessType.UPDATE)
//    @PutMapping
//    public AjaxResult edit(@RequestBody SysConsultation sysConsultation) {
//        return toAjax(sysConsultationService.updateSysConsultation(sysConsultation));
//    }
    /**
     * 修改用户的咨询请求进行状态管理（未处理，已处理，暂不处理）
     */
    @PreAuthorize("@ss.hasPermi('system:consultation:edit')")
    @PutMapping
    public AjaxResult edit(@PathVariable("id") Long id,String status) {
        return toAjax(sysConsultationService.updatestatus(id,status));
    }
    /**
     * 删除通知公告
     */
    @PreAuthorize("@ss.hasPermi('system:consultation:remove')")
    @Log(title = "通知公告", businessType = BusinessType.DELETE)
	@DeleteMapping("/{noticeIds}")
    public AjaxResult remove(@PathVariable Long[] noticeIds)
    {
        return toAjax(sysConsultationService.deleteSysConsultationByNoticeIds(noticeIds));
    }
}
